/*
* @Author: nccloud
* @PageInfo: 卡片表体删行
*/
import { AREA, BUTTONID } from '../../constance';

export default function(props, moduleId, record, index) {
        if (record && index >= 0) {
                // 列操作
                props.cardTable.delRowsByIndex(moduleId, index);
                // 按钮可用性
                if (props.cardTable.getNumberOfRows(moduleId) > 0) {
                        let checkArr = props.cardTable.getCheckedRows(moduleId);
                        if (!checkArr || checkArr.length < 1) {
                                props.button.setDisabled(getHeadButtonIds(moduleId), true);
                        } else {
                                props.button.setDisabled(getHeadButtonIds(moduleId), false);
                        }
                }
        } else {
                // 肩操作
                let checkArr = props.cardTable.getCheckedRows(moduleId);
                let rowIndexes = [];
                if (checkArr && checkArr.length > 0) {
                        checkArr.forEach((row) => {
                                rowIndexes.push(row.index);
                        });
                        props.cardTable.delRowsByIndex(moduleId, rowIndexes);
                        // 按钮可用性
                        props.button.setDisabled(getHeadButtonIds(moduleId), true);
                }
        }
}

function getHeadButtonIds(moduleId) {
        let buttonIds;

        switch (moduleId) {
                        case AREA.cardBody_1:
                buttonIds = [ BUTTONID.cardBody_1_DeleteLine, BUTTONID.cardBody_1_CopyLine ];
                break;
                case AREA.cardBody_2:
                buttonIds = [ BUTTONID.cardBody_2_DeleteLine, BUTTONID.cardBody_2_CopyLine ];
                break;
        }
        return buttonIds;
}
